package com.blast.comicsisland.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.blast.comicsisland.R;
import com.blast.comicsisland.model.commic.commiccatalog.BookPart;

import java.util.List;

/**
 * Created by Android Studio
 * Author: hg
 * Date: 15/6/30
 * Email: 531057892@qq.com
 */
public class ChapterAdapter extends BaseAdapter {

    private Context context;
    private List<BookPart> bookParts;

    public ChapterAdapter(Context context, List<BookPart> bookParts) {
        this.context = context;
        this.bookParts = bookParts;
    }

    @Override
    public int getCount() {
        int ret = 0;
        if (bookParts != null) {
            ret = bookParts.size();
        }
        return ret;
    }

    @Override
    public Object getItem(int position) {
        Object ret = null;
        if (bookParts != null) {
            ret = bookParts.get(position);
        }
        return ret;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View ret = null;
        if (convertView != null) {
            ret = convertView;
        }else {
            ret = LayoutInflater.from(context).inflate(R.layout.item_chapter_grid_view,null);
        }

        ViewHolder holder = (ViewHolder) ret.getTag();

        if (holder == null) {
            holder = new ViewHolder();
            holder.txtContent = (TextView) ret.findViewById(R.id.item_chapter_text_view);
            ret.setTag(holder);
        }
        BookPart bookPart = bookParts.get(position);
        String name = bookPart.getName();
        holder.txtContent.setText(name);

        return ret;
    }


    class ViewHolder {
        private TextView txtContent;
    }

}
